package com.CGFrame.struts.action.project;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.CGFrame.struts.POJOs.Catemodel;
import com.CGFrame.struts.POJOs.Elementgroup;
import com.CGFrame.struts.bean.ProjectOperate;
import com.CGFrame.struts.bean.ProjectOperateFactory;
import com.CGFrame.struts.bean.project.ProjectBean;
import com.CGFrame.struts.bean.unit.ElementGroupBean;

public class IndexElementModelAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		String projectId=request.getParameter("projectId");
		ProjectBean pb=new ProjectBean(projectId);
		for(Iterator iter=pb.getElementgroups().iterator();iter.hasNext();){
			Elementgroup eg=(Elementgroup)iter.next();
			if(eg.getElementgroup()==null){
				ElementGroupBean egb=new ElementGroupBean(eg);
				LinkedHashSet list1=egb.getAllElements();
				Set set1=eg.getElementgroups();
				request.setAttribute("elementList", list1);//所有元素
				request.setAttribute("elementGroupList", set1);//元素的种类
			}
		}
		ProjectOperate pop=ProjectOperateFactory.getprojectOperate();
		List models=pop.Query("Catemodel", null, null, null);
		List elementModels=new ArrayList();
		for(Iterator iter=models.iterator();iter.hasNext();){
			Catemodel model=(Catemodel)iter.next();
			if(model.getCateModelType().equals("Element")){
				elementModels.add(model);
			}
		}
		request.setAttribute("elementModels", elementModels);
		request.setAttribute("projectId", projectId);
		return mapping.findForward("success");
	}
	
}
